#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
const ll N=1e5+5;
int st[N], tt;
ll n;
void solve()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        while(tt&&st[tt]>=x)
            tt--;

        if(tt) cout<<st[tt]<<" ";
        else cout<<"-1"<<" ";

        st[++tt]   = x;
    }

}
int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
